<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>    
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html PUBLIC>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/board.css" />
<script type="text/javascript" src="./js/util.js"></script>
<script type="text/javascript">
function checkForm(f) {
	var result = true;
	if(isNull(f.memo, document.getElementById("error_memo"), "덧글을 입력하세요!!")) result = false;
	return result;
}
</script>
<title>Insert title here</title>
</head>
<body>
<div id='boardFrm' align="center">
	<!-- 상단 타이틀 이미지 -->
	<div align = "left" style = "margin-bottom: 20px; margin-top: 20px;">
		<img src = "images/board/recomen_tt.gif"/>
	</div>
</div>
	<!-- 게시판 상세보기 -->
	<div id = 'notice_list_top' align = "center">
	
		<div class = "top_detail" align = "left">
			<label class = "board_title">${board.title}</label><br/>
			<label class = "board_detail_editor">${board.writer}</label>
			<label class = "board_detail_date"><fmt:formatDate value="${board.wdate}" pattern="yyyy-MM-dd" /></label>
			<label class = "board_detail_hit">${board.hit}</label>
		</div>
		<div class = "content_detail">
		 	${board.content}
		</div>
	</div>
	
	<p/>
	
	<div id = 'notice_detail_btn' align = "right">
		<input  class = "notiBtn" type = "button" value = '목록으로' style="background: #AA1212; color: white;"
		onclick="location.href='recommend.do?page=1'">
		
		<c:if test="${board.writer == sessionUser}">
		<input  class = "notiBtn" type = "button" value = '수정'
		onclick="location.href='recom_write.do?idx=${board.idx}&page${page}&action=update'" />
		<input  class = "notiBtn" type = "button" value = '삭제'
		onclick="location.href='recom_delete.do?idx=${board.idx}'" />
		</c:if>
		<c:if test="${prev != null}">
		<input class="notiBtn" type="button" value="이전글" onclick="location.href='recom_detail.do?idx=${prev.idx}'" />
		</c:if>
		<c:if test="${next != null}">
		<input class="notiBtn" type="button" value="다음글" onclick="location.href='recom_detail.do?idx=${next.idx}'" />
		</c:if>
		</div>
		
	<!-- 답글 쓰기 -->
		<%
		if(session.getAttribute("email") != null){
		%>
		
<form:form modelAttribute="reply" action="save.do" method="post" onsubmit="return checkForm(this)">

	<div align="center" id = 'reply_Frm'>
	
		<div align="left" style = "margin-top: 5px;">
		<span style = "font-size: 15px; font-family: 맑은 고딕; font-weight: bold;
		margin-left: 10px;color: #5D5D5D">덧글을 작성해주세요 :)</span><p/>
		</div>
	
		<input type="hidden" name="action" value="reply" />
		<input type="hidden" name="idx" value="${board.idx}" />
		<input type="hidden" name="page" value="${page}" />
		<input type="hidden" name="writer" value=<%=session.getAttribute("nick_name") %>>
		
		<div class = 'reply_input' align="left">
			<form:input path="memo" name="memo" size="130" class= 'formTag'/>
				
				<div align="center" style = "display: inline-block;">
					<input class = "replyBtn" type="submit" value="확인" />
				</div>
			<br/>	
			<span class="error-text" id="error_memo"></span>
		</div>
		
	</div>
	
</form:form>
<%
}
%>
		<!-- 답글 목록 -->
		<c:if test="${not empty replies}">
		<div align="center" id = 'reply_Frm' style = "margin-top: 20px;">
		
		<div align="left" style = "margin-top: 5px; margin-bottom: 10px;">
		<span style = "font-size: 15px; font-family: 맑은 고딕; font-weight: bold;
		margin-left: 10px; color: #5D5D5D;"><u>덧글 목록</u></span>
		</div>
			
	<c:forEach items="${replies}" var="reply">
	
		<div align="left" id= "reply_list">
			<span class = "writer">${reply.writer}</span>
			
			<span class = "memo">${reply.memo}
			<c:if test="${reply.writer == sessionUser}">
		    <span class="small"><a href="reply.do?idx=${board.idx}&page=${page}&rno=${reply.idx}&action=del_repl">X</a></span>
		    </c:if>
		    </span>
			
			<span class = "wdate"><fmt:formatDate value="${reply.wdate}" pattern="yyyy-MM-dd"/></span>
		</div>
	</c:forEach>
		</div>
		</c:if>

	<div style = "height: 30px;"></div>

</body>
</html>